﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using _250210作业.BLL;
using MVCProject.UI;

namespace _250210作业.API.Controllers
{
    public class GoodsController : ApiController
    {
        // GET: api/Goods
        public List<UniAppGoodJsonDto> Get()
        {
            GoodsTypeBLL bll = new GoodsTypeBLL();
            var types = bll.Query();
            ResultData<List<UniAppGoodJsonDto>> result = new ResultData<List<UniAppGoodJsonDto>>();
            var list = from t in types
                       select new UniAppGoodJsonDto
                       {
                           id = t.gtId,
                           name = t.name,
                           icon = t.icon,
                           is_show_backstage = t.is_show_backstage,
                           sort = t.sort,
                           goods_list = from g in t.Goods
                                        select new UniAppGoodDto
                                        {
                                            id = g.gId,
                                            name = g.name,
                                            content = g.content,
                                            images = g.images,
                                            use_spec = g.use_spec,
                                            use_property = g.use_property,
                                            unit = g.unit,
                                            price = g.price,
                                            sales = g.sales,
                                            sort = g.sort,
                                            property = from p in g.GoodsPropertyKey
                                                       select new UniAppGoodPropertyKeyDto
                                                       {
                                                           id = p.gpkId,
                                                           name = p.GoodsSpecKey.name,
                                                           values = from v in p.GoodsPropertyValue
                                                                    select new UniAppGoodPropertyValueDto
                                                                    {
                                                                        id = v.gpvId,
                                                                        is_default = v.is_default,
                                                                        code = v.GoodsSpecValue.code,
                                                                        value = v.GoodsSpecValue.value
                                                                    }
                                                       }

                                        }
                       };

            return list.ToList();
        }

        // GET: api/Goods/5
        public string Get(int id)
        {
            return "value";
        }

        // POST: api/Goods
        public void Post([FromBody] string value)
        {
        }

        // PUT: api/Goods/5
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE: api/Goods/5
        public void Delete(int id)
        {
        }
    }
}
